<?php

/**
 * Created by PhpStorm.
 * User: zhangyurong
 * Date: 2016/7/22
 * Time: 8:33
 */
namespace App\Repositories\Eloquent; 
use App\Facades\Site as StyleSite;
use App\Repositories\Contracts\StyleContract;

class StyleService implements StyleContract{
    /**
     * @param $tplfile
     * @param array $tpldata
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function view($tplfile,$tpldata=array()){
        return view($this->file($tplfile), $tpldata);
    }

    /**
     * @param $path
     * @return string
     */
    public function file($path)
    {
//        $template = 'default';
        $template=empty(StyleSite::get('template'))?'default':StyleSite::get('template');
        $view = $template.'.'.$path;
        if ($template!='default' && view()->exists($view)) {
            return $view;
        }else{
            return 'default.'.$path;
        }
    }

    /**
     * @param $path
     * @return string
     */
    public function url($path)
    {
        return '/default'.$path;
    }

    /**
     * @param $url
     * @return string
     */
    public function asset($url){
        return asset($this->url($url));
    }
}